package com.yst.gateway.monitor.common.beans;

/**
 * JSON统一响应结构,该响应结构如下：
{
	"meta": {
		"success": true,
		"message": "ok"
	},
	"data": ...
}
 * @author sheungxin
 *
 */

public class Response {
	
	private static final String OK = "ok";
	private static final String ERROR ="error";
	private Meta meta;
	private Object data;
	
	public Response success() {
		this.meta = new Meta(true, OK);
		return this;
	}
	
	public Response success(Object data) {
		this.meta = new Meta(true, OK);
		this.data = data;
		return this;
	}
	
	public Response failure() {
		this.meta = new Meta(false, ERROR);
		return this;
	}
	
	public Response failure(String message){
		this.meta = new Meta(false,message);
		return this;
	}
	
	public Response failure(String messageCode,String message){
		this.meta = new Meta(false,messageCode,message);
		return this;
	}
	
	public Meta getMeta() {
		return meta;
	}
	
	public Object getData() {
		return data;
	}
		
	public class Meta {
		private boolean success;
		private String message;
		private String messageCode;
		
		public Meta(){
			
		}
		
		public Meta(boolean success) {
			this.success = success;
		}
		
		public Meta(boolean success, String message) {
			this.success = success;
			this.message = message;
		}
		
		public Meta(boolean success, String messageCode,String message) {
			this.success = success;
			this.message = message;
			this.messageCode=messageCode;
		}
		
		public boolean isSuccess() {
			return success;
		}
		
		public String getMessage() {
			return message;
		}

		public String getMessageCode() {
			return messageCode;
		}
	}
}
